import axios from 'axios'
export const service = axios.create({
  baseURL: window.apiUrl
})

service.interceptors.request.use(
  config => {
    if (config.responseType) {
      config.responseType = 'blob'
    }
    return config
  },
  error => {
    return Promise.reject(new Error(error))
  }
)

// 生产管控甘特图 <========
const mookData = [
  {
    makeSerialNumber: '区域1', // 区域
    workStation: '型架1', // 设备
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 18:00:00', state: '运行' },
      { startTime: '2025-08-31 18:00:00', filingTime: '2025-08-31 20:22:35', state: '充电' },
      { startTime: '2025-08-31 20:22:35', filingTime: '2025-09-01 08:00:00', state: '待机' },
      { startTime: '2025-09-01 08:00:00', filingTime: '2025-09-04 08:00:00', state: '故障' }
    ]
  },
  {
    makeSerialNumber: '区域2',
    workStation: '型架2',
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 10:00:00', state: '充电' },
      { startTime: '2025-08-31 11:00:00', filingTime: '2025-08-31 18:00:00', state: '待机' },
      { startTime: '2025-09-01 08:00:05', filingTime: '2025-09-01 12:00:00', state: '运行' },
      { startTime: '2025-09-01 13:00:00', filingTime: '2025-09-04 18:00:00', state: '运行' }
    ]
  },
  {
    makeSerialNumber: '区域3', // 区域
    workStation: 'AGV1', // 设备
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 18:00:00', state: '报警' },
      { startTime: '2025-08-31 18:00:00', filingTime: '2025-09-01 20:22:35', state: '充电' }
    ]
  },
  {
    makeSerialNumber: '区域4', // 区域
    workStation: 'AGV2', // 设备
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 12:00:00', state: '运行' },
      { startTime: '2025-08-31 12:00:00', filingTime: '2025-08-31 13:22:35', state: '待机' },
      { startTime: '2025-08-31 13:22:35', filingTime: '2025-09-01 18:00:00', state: '停机' },
      { startTime: '2025-09-01 08:00:00', filingTime: '2025-09-04 08:00:00', state: '充电' }
    ]
  },
  {
    makeSerialNumber: '区域5',
    workStation: '型架3',
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 10:00:00', state: '充电' },
      { startTime: '2025-08-31 11:00:00', filingTime: '2025-08-31 18:00:00', state: '待机' },
      { startTime: '2025-09-01 08:00:05', filingTime: '2025-09-01 12:00:00', state: '运行' },
      { startTime: '2025-09-01 13:00:00', filingTime: '2025-09-04 18:00:00', state: '运行' }
    ]
  },
  {
    makeSerialNumber: '区域6', // 区域
    workStation: '型架4', // 设备
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 11:00:00', state: '报警' },
      { startTime: '2025-08-31 11:00:00', filingTime: '2025-09-01 20:22:35', state: '停机' }
    ]
  },
  {
    makeSerialNumber: '区域7', // 区域
    workStation: 'AGV3', // 设备
    deviceStates: [
      { startTime: '2025-09-01 08:00:00', filingTime: '2025-09-01 18:00:00', state: '运行' },
      { startTime: '2025-09-02 18:00:00', filingTime: '2025-09-02 20:22:35', state: '充电' }
    ]
  },
  {
    makeSerialNumber: '区域8', // 区域
    workStation: 'AGV4', // 设备
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 18:00:00', state: '充电' },
      { startTime: '2025-08-31 18:00:00', filingTime: '2025-08-31 20:22:35', state: '充电' },
      { startTime: '2025-08-31 20:22:35', filingTime: '2025-09-01 08:00:00', state: '待机' },
      { startTime: '2025-09-01 08:00:00', filingTime: '2025-09-04 08:00:00', state: '故障' }
    ]
  },
  {
    makeSerialNumber: '区域9',
    workStation: '型架5',
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 10:00:00', state: '充电' },
      { startTime: '2025-08-31 11:00:00', filingTime: '2025-08-31 18:00:00', state: '待机' },
      { startTime: '2025-09-01 08:00:05', filingTime: '2025-09-01 12:00:00', state: '运行' },
      { startTime: '2025-09-01 13:00:00', filingTime: '2025-09-04 18:00:00', state: '运行' }
    ]
  },
  {
    makeSerialNumber: '区域10', // 区域
    workStation: '型架6', // 设备
    deviceStates: [
      { startTime: '2025-08-31 08:00:00', filingTime: '2025-08-31 18:00:00', state: '检修' },
      { startTime: '2025-08-31 18:00:00', filingTime: '2025-09-01 20:22:35', state: '充电' }
    ]
  }
]
export const getHongduPlanList = (params) => {
  const { makeSerialNumber, workStation } = params
  const data = mookData.filter(item => {
    if (makeSerialNumber) {
      return item.makeSerialNumber === makeSerialNumber
    } else if (workStation) {
      return item.workStation === workStation
    } else {
      return item
    }
  })

  return Promise.resolve({
    data: { data }
  })
}

// =======>
